/*LICENSE_BEGIN
 * ******************************************************************
 * Copyright 2006 by the Dainamite Robocup-Team at the
 * DAI-Labor, TU-Berlin (www.dai-labor.de)
 * 
 * Members of Dainamite are:
 * Holger Endert
 * Robert Wetzker
 * Thomas Karbe
 * Axel Heßler
 * Philippe Bütter
 * Felix Brossmann
 * 
 * Licensed under the GNU GPL (General Public License) Free Software 
 * License, Version 2. You may use this file only in compliance with 
 * the License. You may obtain a copy of the License at:
 * 
 * http://www.fsf.org/licensing/licenses/gpl.txt
 * ******************************************************************
LICENSE_END*/
package robocup.component.infotypes;

import robocup.component.PConf;

/**
 * The PlayerTypesInfo is a collection of heterogeneous player types.
 * These were received one after another, and subsequently added to this
 * info object.
 */
public class PlayerTypesInfo extends Info {

	/**
	 * The received player-types.
	 */
	public PConf playerTypes[];

	/**
	 * The amount of already received player-types.
	 */
	private int filled = 0;

	/**
	 * Constructor, sets the infoType to TYPE_PTYPE! Contains all heterogeneous
	 * playerType-data, that are defined within the server and sent to the
	 * agents.
	 */
	public PlayerTypesInfo() {
		super(-1);
		this.infoType = Info.TYPE_PTYPE;
	}

	/**
	 * Sets the number of playertypes
	 * 
	 * @param noOfTypes
	 */
	public void setNoOfPlayerTypes(int noOfTypes) {
		this.playerTypes = new PConf[noOfTypes];
	}

	/**
	 * Retrives the number of playertypes
	 * 
	 * @return - the number of available types
	 */
	public int getNoOfPlayerTypes() {
		return this.playerTypes.length;
	}

	/**
	 * Adds a new player type to the array
	 * 
	 * @param pc
	 */
	public void fillInType(PConf pc) {
		if (this.playerTypes != null) {
			if (this.filled < this.playerTypes.length) {
				this.playerTypes[this.filled] = pc;
				this.filled++;
			}
		} else {
			this.playerTypes = new PConf[7];
			this.playerTypes[0] = pc;
			this.filled++;
		}
	}

	/**
	 * Retrieves a player type
	 * 
	 * @param i -
	 *            the index of the type
	 * @return - PConf of the type, or null, if not available for index i
	 */
	public PConf getType(int i) {
		if (this.playerTypes.length >= i - 1)
			return this.playerTypes[i];
		return null;
	}

	/**
	 * retrieves all playertypes
	 * 
	 * @return an array containing all possible player types in PConf format!
	 */
	public PConf[] getPlayerTypes() {
		return this.playerTypes;
	}

	/**
	 * This method checks if all player types have been collected!
	 * 
	 * @return true, if the number of available playertypes is 7
	 */
	public boolean playerTypesFull() {
		if (this.playerTypes == null)
			return false;
		return (this.filled == this.playerTypes.length);
	}
}
